package bspool;

import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.*;

public class Server {
    public static void main(String[] args) throws Exception
    {
        System.out.println("==服务端启动==");
        //1.创建一个TCP服务端Socket对象
        ServerSocket ss = new ServerSocket(8080);
        ThreadPoolExecutor pool = new ThreadPoolExecutor(14 * 2,
                14 * 2,
                0,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<Runnable>(8),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.CallerRunsPolicy()
        );

        //2、客户端对应的管道对象交给一个线程池对象处理
        try {
            while(true){
                Socket socket = ss.accept();
                System.out.println("一个客户端上线了！" + socket.getInetAddress().getHostAddress());
                pool.submit(new ServerReader(socket));

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
